{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# The ``inline`` flag will use the appropriate backend to make figures appear inline in the notebook.  \n",
    "%matplotlib inline\n",
    "\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "# `plt` is an alias for the `matplotlib.pyplot` module\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "# import seaborn library (wrapper of matplotlib)\n",
    "import seaborn as sns"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Load Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load car loan data into a pandas dataframe from a csv file\n",
    "filename = 'data/table_i702t60.csv'\n",
    "df = pd.read_csv(filename)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# View the first 5 rows of the dataframe\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Checking to make sure we dont have nans in our dataframe\n",
    "# It is not easy to directly plot data that contains nans\n",
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# For this notebook we will graph interest_paid, principal_paid, and month on one graph\n",
    "# While we could graph directly through pandas, we will graph through matplotlib for now.\n",
    "month_number = df.loc[:, 'month'].values\n",
    "interest_paid = df.loc[:, 'interest_paid'].values\n",
    "principal_paid = df.loc[:, 'principal_paid'].values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "month_number"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# The values attribute converts a column of values into a numpy array\n",
    "type(month_number)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Grids"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.plot(month_number, interest_paid, c= 'k')\n",
    "plt.plot(month_number, principal_paid, c = 'b')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### MATLAB-style"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.plot(month_number, interest_paid, c= 'k')\n",
    "plt.plot(month_number, principal_paid, c = 'b')\n",
    "plt.grid()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# only horizontal grid lines\n",
    "plt.plot(month_number, interest_paid, c= 'k')\n",
    "plt.plot(month_number, principal_paid, c = 'b')\n",
    "plt.grid(axis = 'y')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# only vertical grid lines\n",
    "plt.plot(month_number, interest_paid, c= 'k')\n",
    "plt.plot(month_number, principal_paid, c = 'b')\n",
    "plt.grid(axis = 'x')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# change color of grid lines, transparency, and linestyle\n",
    "plt.plot(month_number, interest_paid, c= 'k')\n",
    "plt.plot(month_number, principal_paid, c = 'b')\n",
    "plt.grid(c = 'g', \n",
    "         alpha = .9,\n",
    "         linestyle = '-')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Object-oriented"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig, axes = plt.subplots(nrows = 1, ncols = 1);\n",
    "axes.plot(month_number, interest_paid, c= 'k');\n",
    "axes.plot(month_number, principal_paid, c = 'b');\n",
    "axes.grid()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# only horizontal grid lines\n",
    "fig, axes = plt.subplots(nrows = 1, ncols = 1);\n",
    "axes.plot(month_number, interest_paid, c= 'k');\n",
    "axes.plot(month_number, principal_paid, c = 'b');\n",
    "axes.grid(axis = 'y')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# only vertical grid lines\n",
    "fig, axes = plt.subplots(nrows = 1, ncols = 1);\n",
    "axes.plot(month_number, interest_paid, c= 'k');\n",
    "axes.plot(month_number, principal_paid, c = 'b');\n",
    "axes.grid(axis = 'x')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# change color of grid lines, transparency, and linestyle\n",
    "fig, axes = plt.subplots(nrows = 1, ncols = 1);\n",
    "axes.plot(month_number, interest_paid, c= 'k');\n",
    "axes.plot(month_number, principal_paid, c = 'b');\n",
    "axes.grid(c = 'g', \n",
    "          alpha = .9,\n",
    "          linestyle = '-')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# if you are finding setting grids to be tedious, use a style that has grids\n",
    "plt.style.use('seaborn')\n",
    "fig, axes = plt.subplots(nrows = 1, ncols = 1);\n",
    "axes.plot(month_number, interest_paid, c= 'k');\n",
    "axes.plot(month_number, principal_paid, c = 'b');"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
